/*wzXrLLQizH4J3+wYgxi4e2b3ep99vQHSBtITcJjofM7iXVe6EFc/a5YRGeWQomog*/
import React, { Component } from 'react';
import { createPage, base,ajax,toast} from 'nc-lightapp-front';
let { NCButton, NCModal} = base;
import OrgSelect  from './OrgSelect';
var EMPTY_FN = function(){};
class AssignModal extends Component {
    constructor(props) {
        super(props);
        this.state = {
            modal:{
                show: false,
                modalDropup: true,
                size: 'xlg',
                backdrop:false/"static",//是否弹出遮罩层/点击遮罩层是否触发关闭事件
                fieldid:"supplierassign_modal-area"
            },
        }
        this.onFinish = this.props.onFinish || EMPTY_FN;
    }
    componentDidMount(){
        this.show();
    }
    show(flag){
        this.state.modal.show = true;
        this.setState(this.state, ()=>{
            this.orgSelect.reset();
        });
        this.props.isAssign = flag ==='assign'?true:false;

    }

    onsubmit(){
        debugger
        let targetOrgIds = [];
        this.orgSelect.state.selectData.datas
        &&this.orgSelect.state.selectData.datas.map((item)=>{
            targetOrgIds.push(item['id']);
        });

        let formitem = this.props.form.getFormItemsValue(this.props.formId,'pk_customer');
        let custpks ='1234'

        targetOrgIds.length===0?toast({
            'color':'danger',
            'content':'请选择目标组织！'
            }): ajax({
            url:'/nccloud/uapbd/customer/custAssign.do',
            data:{
                pkcustList:[custpks],
                targetOrgIds:targetOrgIds,
                isAssign:this.props.isAssign,
                nodeType:this.props.nodeType,
                pk_curOrg:this.props.envParam.pk_org
            },
            success:(res)=>{
                let{success,data} = res;
                if(success){
                    if(data&&data.hasOwnProperty('message')){
                        toast({'color':'success','content':data.message});
                        this.cancel();
                    }
                }
            }
        });
       }
    cancel(){
        this.state.modal.show = false;
        this.setState(this.state);
    }


    render() {
        var modalCfg = {...this.state.modal}
        return (
            <NCModal {...modalCfg} onHide = {this.cancel.bind(this)} fieldid = 'assignmodal'>
                <NCModal.Header closeButton={true}>
                    <NCModal.Title>{this.props.isAssign?'快速分配':'快速取消分配'}</NCModal.Title>
                </NCModal.Header>
                <NCModal.Body>
                    <div><OrgSelect ref={( item )=> this.orgSelect = item}/></div>
                </NCModal.Body>
                <NCModal.Footer>

                    <NCButton fieldid = 'confirm' onClick={ this.onsubmit.bind(this) }>确定</NCButton>
                    <NCButton fieldid = 'cancel' onClick={ this.cancel.bind(this) }>取消</NCButton>
                </NCModal.Footer>
            </NCModal>
        );
    }
}
export default AssignModal;
/*wzXrLLQizH4J3+wYgxi4e2b3ep99vQHSBtITcJjofM7iXVe6EFc/a5YRGeWQomog*/
